package base.adapter;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext;

/**
 * Created by wuhui on 2016/8/8.
 */
public class EchoHandlerAdp extends ChannelHandlerAdapter{

    @Override
    public void channelActive(final  ChannelHandlerContext ctx) throws Exception {
        ctx.writeAndFlush(123); // (3)
//        final ByteBuf time = ctx.alloc().buffer(4); // (2)
//        time.writeInt((int) (System.currentTimeMillis() / 1000L + 2208988800L));
//
//        final ChannelFuture f = ctx.writeAndFlush(time); // (3)
//        f.addListener(new ChannelFutureListener() {
//
//            @Override
//            public void operationComplete(ChannelFuture future) {
//                assert f == future;
//                //ctx.close();
//            }
//        }); // (4)

    }
//
//    @Override
//    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
//        System.out.println(msg);
//        //super.channelRead(ctx, msg);
//        //ctx.writeAndFlush(msg);//把这个消息直接返回到发送数据来的地方
//        ctx.fireChannelRead(msg);//把这个消息发送到下一个adapter里取，类似web环境中fifter的dofifter方法 ，责任链方法
//    }
}
